package com.china08.yxyapi.api.manage.edu.office.meetingv1_1;

import java.text.ParseException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.meeting.VideoMeeting;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.VideoMeetingRepository;
import com.china08.yxyapi.service.baijiayun.impl.MeetingRoomServiceImpl;

/**
 * 取消视频会议
 *
 */
@RestController("edu_meeting_update")
public class VideoMeetingv1_1UpdateController extends YxyApiBaseController {

    @Autowired
    private VideoMeetingRepository videoMeetingRepository;

    @Autowired
    private MeetingRoomServiceImpl meetingRoomServiceImpl;

    @RequestMapping(value = "/api_yw/manage/edu/office/meetingv1_1/videomeet/udp", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel)
            throws ParseException {

        reqModel.check();

        RespModel model = new RespModel();
        VideoMeeting vMeeting = videoMeetingRepository.findOne(reqModel.id);

        Assert.isTrue(vMeeting != null, "该视频会议不存在");

        vMeeting.setCause(reqModel.reason);
        vMeeting.setStatus(-1);
        vMeeting = videoMeetingRepository.save(vMeeting);
        meetingRoomServiceImpl.meetingRoomDel(vMeeting.getId());

        model.setMessage("取消会议成功");
        return model;
    }

    /**
     * 请求参数
     * 
     */
    protected static class ReqModel extends YxyApiPageReqModel {
        // 会议id
        public String id;
        // 原因
        public String reason;

        public void check() {
            Assert.notNull(StringUtils.defaultIfBlank(id, null), "会议编号不能为空");
            Assert.notNull(StringUtils.defaultIfBlank(reason, null), "请输入1-500个字的取消会议原因");
            Assert.isTrue(reason.length() <= 500, "请输入1-500个字的取消会议原因");
        }
    }

    /**
     * 响应参数
     * 
     */
    protected static class RespModel extends YxyApiRespModel {

    }
}
